﻿
Namespace LightSwitchApplication

    Public Class OrderHeader

        Private Sub OrderHeader_Created()

            Me.OrderNumber = (Date.Today.Year) & Date.Today.Month & Date.Today.Day & (Me.Id)
            Me.OrderDate = Date.Today
            Me.OrderStatus = "Created"
            Me.LoadDate = Date.Today.AddDays(1)
            Me.UnloadDate = Date.Today.AddDays(2)
            Me.CommissionAmount = 0
            Me.TDS = 0
            Me.NetAmount = 0
            Me.Quantity = 12
            Me.TDSPercent = 0.1
            Me.CommissionPercent = 0.06

            Me.PaidBy = "Destination"
            'Me.CommissionAmount = CommissionPercent * TotalCharge
            'Me.TDS = TDSPercent * TotalCharge
            'Me.NetAmount = TotalCharge - (TDS + CommissionAmount)
        End Sub

        Private Sub TotalCharge_Changed()
            Me.CommissionAmount = CommissionPercent * TotalCharge
            Me.TDS = TDSPercent * TotalCharge
            Me.NetAmount = TotalCharge - (TDS + CommissionAmount)
        End Sub

        Private Sub TDSPercent_Changed()
            'Me.CommissionAmount = CommissionPercent * TotalCharge
            Me.TDS = TDSPercent * TotalCharge
            Me.NetAmount = TotalCharge - (TDS + CommissionAmount)
            'Call CalculateOrder()
        End Sub
       

        Private Sub CommissionPercent_Changed()
            If CommissionPercent <> 0 Then
                Me.CommissionAmount = CommissionPercent * TotalCharge
                ' Me.TDS = TDSPercent * TotalCharge
                Me.NetAmount = TotalCharge - (TDS + CommissionAmount)
                ' Call CalculateOrder()
            Else
                CommissionAmount = 0
            End If
           
        End Sub
        Private Sub CalculateOrder()


            Me.NetAmount = TotalCharge - (TDS + CommissionAmount)
        End Sub

        Private Sub PaidAmount_Compute(ByRef result As System.Nullable(Of Decimal))
            ' Set result to the desired field value
            Dim res = 0
            For Each PaymentDetail In PaymentDetails
                res = res + PaymentDetail.Amount
            Next
            result = res
        End Sub

        Private Sub Carrier_Changed()
            'Me.TruckOwner = DataWorkspace.ApplicationData.TruckOwners.Where(Function(town) town.Id = Me.Carrier.TruckOwner.Id).FirstOrDefault
        End Sub

        Private Sub TruckOwner_Changed()
            'Me.C = DataWorkspace.ApplicationData.TruckOwners.Where(Function(town) town.Carriers = Me.Carrier).FirstOrDefault

        End Sub

        Private Sub OrderNumber_Validate(results As EntityValidationResultsBuilder)
            ' results.AddPropertyError("<Error-Message>")

        End Sub
    End Class

End Namespace
